package cool.webstudy.admin.controller.competition.team;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cool.webstudy.admin.constant.enums.RoleEnum;
import cool.webstudy.admin.model.dto.competition.PaginationQueryCompetitionInfoListDTO;
import cool.webstudy.admin.model.dto.competition.QueryCompetitionDetailInfoDTO;
import cool.webstudy.admin.model.dto.competition.question.PaginationQueryCompetitionQuestionInfoListDTO;
import cool.webstudy.admin.model.dto.competition.team.PaginationQueryCompetitionTeamInfoListDTO;
import cool.webstudy.admin.model.vo.competition.question.PaginationQueryCompetitionQuestionInfoListVO;
import cool.webstudy.admin.model.vo.competition.team.PaginationQueryCompetitionTeamInfoListVO;
import cool.webstudy.admin.model.vo.competition.team.QueryCompTeamDetailWithLoginInfoVO;
import cool.webstudy.admin.model.vo.competition.team.QueryCompTeamHostNetInfoVO;
import cool.webstudy.admin.model.vo.competition.team.QueryOwnCompTeamHostWithLoginInfoVO;
import cool.webstudy.admin.model.vo.user.QueryUserDetailInfoVO;
import cool.webstudy.admin.service.CompetitionService;
import cool.webstudy.admin.service.CompetitionTeamService;
import cool.webstudy.admin.utils.aspect.permissions.PermissionsCheck;
import cool.webstudy.admin.utils.aspect.request.RequestParameterCheck;
import cool.webstudy.admin.utils.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 莫振双
 * @date 2025/3/23 18:53
 * @description: 赛事队伍管理接口控制器
 */
@Tag(name = "参赛队伍管理")
@RestController
@RequestMapping("/competition/team")
@RequestParameterCheck
public class CompetitionTeamController {
    @Autowired
    private CompetitionTeamService competitionTeamService;
    @Autowired
    private CompetitionService competitionService;

    @PostMapping("/page-query/list")
    @Operation(summary = "分页查询参赛队伍信息列表接口")
    @PermissionsCheck(role = RoleEnum.ADMIN)
    public Result<Page<PaginationQueryCompetitionTeamInfoListVO>> paginationQueryList(@RequestBody PaginationQueryCompetitionTeamInfoListDTO dto) {
        Page<PaginationQueryCompetitionTeamInfoListVO> vo = competitionTeamService.paginationQueryCompetitionTeamInfoList(dto);
        return Result.success(vo);
    }
    @GetMapping("/query/detail-info")
    @Operation(summary = "查询参赛队伍详细信息接口")
    public Result queryDetailInfo(@RequestParam String unCode) {
        QueryCompTeamDetailWithLoginInfoVO vo = competitionTeamService.queryCompTeamDetailWithLoginInfo(unCode);
        return Result.success(vo);
    }
    @GetMapping("/query/own-team-host/detail/info")
    @Operation(summary = "查询当前登录用户所属队伍参赛主机详细信息接口")
    public Result queryOwnTeamHostDetailInfo() {
        QueryOwnCompTeamHostWithLoginInfoVO vo = competitionTeamService.queryOwnCompTeamDetailInfoWithLoginInfo();
        //翻译赛事信息
        QueryCompetitionDetailInfoDTO competitionDetailInfoDTO = competitionService.queryCompetitionDetailInfo(vo.getCompetitionUnCode());
        vo.setCompetitionName(competitionDetailInfoDTO.getName());
        vo.setCompetitionStatus(competitionDetailInfoDTO.getStatusFlag());
        vo.setRoundCount(competitionDetailInfoDTO.getRoundCount());
        vo.setRoundDuration(competitionDetailInfoDTO.getRoundDuration());
        vo.setCurrentRoundCount(competitionDetailInfoDTO.getCurrentRoundCount());
        return Result.success(vo);
    }
    @GetMapping("/query/list/host-net-info")
    @Operation(summary = "查询参赛队伍参赛主机网络信息列表接口")
    public Result<List<QueryCompTeamHostNetInfoVO>> queryListNetInfo(@RequestParam @Schema(description = "赛事业务主键")String competitionUnCode) {
        List<QueryCompTeamHostNetInfoVO> vo = competitionTeamService.queryCompTeamHostNetInfoList(competitionUnCode);
        return Result.success(vo);
    }
}
